﻿$(document).ready(function () {
    //技能等级选择事件
    if ($('#s_jndjp').length > 0) {
        $('#s_jndjp').change(function () {
            var val = $(this).val();
            if (val != '') {
                getAjax('/Common/getjndj?type=2&pid=' + $(this).val(), null, function (data) {
                    $('#s_jndj').html('<option value="">不限</option>' + data);
                });
            } else {
                $('#s_jndj').html('<option value="">不限</option>');
            }
            $('#s_jndjs').html('<option value="">不限</option>');
        });
    }
    if ($('#s_jndj').length > 0) {
        $('#s_jndj').change(function () {
            var val = $(this).val();
            if (val != '') {
                getAjax('/Common/getjndj?type=3&r=' + $('#s_jndjp').val() + '&pid=' + $(this).val(), null, function (data) {
                    $('#s_jndjs').html('<option value="">不限</option>' + data);
                });
            } else {
                $('#s_jndjs').html('<option value="">不限</option>');
            }
        });
    }
    //职业资格证
    if ($('#s_postt').length > 0) {
        $('#s_postt').change(function () {
            var val = $(this).val();
            if (val != '') {
                getAjax('/Common/getpostl?pid=' + $(this).val(), null, function (data) {
                    $('#s_postl').html('<option value="">不限</option>' + data);
                });
            } else {
                $('#s_postl').html('<option value="">不限</option>');
            }
        });
    }


    /* 表弹验证
    --------------------------------------------------*/
    if ($('#Validform').length > 0) {
        $("#Validform").Validform({
            ajaxPost: true,
            datatype: {//传入自定义datatype类型
                "zdata": /^[1-9]?\d{1}(\.\d+)?$/,
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
                //大于0的整数
                "zzzs": /^[1-9]\d{0,}$/,
                //大于0的数
                "zs": /^[ + ]?(0\.\d+)|([1-9][0-9]*(\.\d+)?)$/
            },
            tiptype: (m, o, c) => {
                if (o.type === 3) {
                    layer.alert(m);
                }
            },
            callback: function (data) {
                if (data.url != 'no') {
                    //$.Showmsg(data.Message + ' 马上跳转...');
                    layer.alert(data.Message + ' 马上跳转...');
                } else {
                    //$.Showmsg(data.Message);
                    layer.alert(data.Message);
                }
                setTimeout(function () {
                    if (data.state) {
                        //$.Hidemsg();
                        layer.close(layer.index)
                    }
                    if (data.url != 'no') {
                        location = data.url;
                    }
                }, 2000);
            }
        });
    }

    if ($('#giveupValid').length > 0) {
        $("#giveupValid").Validform({
            ajaxPost: true,
            callback: function (data) {
                $.Showmsg(data.Message);
                setTimeout(function () {
                    $.Hidemsg();
                    if (data.state) {
                        location.reload();
                    }
                }, 2000);
            }
        });
    }

    if ($('#flashform').length > 0) {
        $("#flashform").Validform({
            ajaxPost: true,
            callback: function (data) {
                if (data.state) {
                    getList();
                    parent.getList();
                }
                $.Showmsg(data.Message);
            }
        });
    }

    if ($("#thisform1").length > 0) {
        $("#thisform1").Validform({
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg,{time:500});
            },
            ajaxPost: true,
            callback: function (data) {
                if (data.state) {
                    tableRenders();
                    if ($('#bsdate').length > 0 && !!('#bstimes').length > 0) {
                        var bsdate = $('#bsdate').val();
                        var bstimes = $('#bstimes').val();
                        if (!!!bsdate) {
                            layer.msg('请先选择考试日期!', {icon: 7, time: 2000});
                            $('#bsdate').focus();
                        }
                        if (!!!bstimes || bstimes == '09:00:00 ~ 00:00:00') {
                            layer.msg('请先选择考试时段!', {icon: 7, time: 2000});
                            $('#bstimes').focus();
                        }

                        $.ajax({
                            url: "/Do/BS/getCanUseRoom",
                            type: "POST",
                            data: {date: bsdate, times: bstimes},
                            dataType: "json",
                            success: function (data) {
                                $('#bsRoom').empty();
                                $(data).each(function (index, room) {
                                    if (room.state)
                                        $('#bsRoom').append('<option value="' + room.id + '">' + room.name + '[' + room.kbrs + ']' + '</option>');
                                });
                                //console.log(data);
                            }
                        });
                    }
                    parent.layer.alert(data.Message, {icon: 1, time: 5000});
                }else
                    //  $.Showmsg(data.Message);
                    parent.layer.alert(data.Message, {icon: 2, time: 5000});
            }
        });
    }

    if ($('#thisform2').length > 0) {
        $("#thisform2").Validform({
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg);
            },
            ajaxPost: true,
            callback: function (data) {
                if (data.state) {
                    tableRenders();
                    layer.msg(data.Message, {icon: 1});
                } else
                    // $.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 2});
            }
        });
    }

    if ($('#thisform3').length > 0) {
        $("#thisform3").Validform({
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg);
            },
            ajaxPost: true,
            callback: function (data) {
                if (data.state) {
                    tableRenders();
                    layer.msg(data.Message, {icon: 1});
                } else
                    //$.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 2});
            }
        });
    }

    if ($('#thisform4').length > 0) {
        $("#thisform4").Validform({
            ajaxPost: true,
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg);
            },
            callback: function (data) {
                if (data.state) {
                    layer.msg(data.Message, {icon: 1});
                    tableRenders();
                } else
                    //  $.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 2});
            }
        });
    }

    if ($('#infosform').length > 0) {
        $("#infosform").Validform({
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg);
            },
            ajaxPost: true,
            callback: function (data) {
                if (data.state) {
                    layer.msg(data.Message, {icon: 1});
                } else
                    layer.msg(data.Message, {icon: 2});
            }
        });
    }

    if ($('#modelform').length > 0) {
        $("#modelform").Validform({
            ajaxPost: true,
            /* tiptype:function(msg){
                 if(msg != "通过信息验证！")
                     layer.msg(msg);
             },*/
            tiptype: (m, o, c) => {
                if (o.type === 3) {
                    layer.alert(m);
                }
            },
            datatype: {//传入自定义datatype类型
                "zdata": /^[1-9]?\d{1}(\.\d+)?$/,
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
                //大于0的整数
                "zzzs": /^[1-9]\d{0,}$/,
                //大于0的数
                "zs": /^[ + ]?(0\.\d+)|([1-9][0-9]*(\.\d+)?)$/
            },
            callback: function (data) {
                if (data.state) {
                    //$.Showmsg(data.Message);
                    //当你在iframe页面关闭自身时
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.alert(data.Message, {icon: 1});
                    parent.layer.close(index); //再执行关闭

                    //parent.parent.layer.alert(data.Message);

                    if (!!parent.getList) {
                        parent.getList();
                    }
                    if (!!parent.document.tablereload) {
                        parent.document.tablereload();
                    }
                    //var index = parent.layer.getFrameIndex(window.name);
                    //parent.layer.close(index);
                } else {
                    //parent.parent.layer.alert(data.Message);
                    //$.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 2});
                    if (!!failCallback) {
                        failCallback(data);
                    }
                }
            }
        });
    }

    if ($('#modelform_reload').length > 0) {
        $("#modelform_reload").Validform({
            ajaxPost: true,
            tiptype: function (msg) {
                if (msg != "通过信息验证！")
                    layer.msg(msg);
            },
            datatype: {//传入自定义datatype类型
                "zdata": /^[1-9]?\d{1}(\.\d+)?$/,
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
                //大于0的整数
                "zzzs": /^[1-9]\d{0,}$/,
                //大于0的数
                "zs": /^[ + ]?(0\.\d+)|([1-9][0-9]*(\.\d+)?)$/
            },
            callback: function (data) {
                if (data.state) {
                    // $.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 1});
                    parent.reloadData();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    // $.Showmsg(data.Message);
                    layer.msg(data.Message, {icon: 2});
                }
            }
        });
    }

    /* if ($('#excelValid').length > 0) {
         $("#excelValid").Validform({
             ajaxPost: true,
             beforeSubmit: function (curform) {
                 curform.ajaxSubmit({
                     type: 'post',
                     dataType: 'json',
                     success: function (data) {
                         //data = $.parseJSON($(data).text());
                         if (data.state) {
                             //parent.$.Showmsg(data.Message);
                             if(data.url!="no"){

                                 /!*var rfrom=$('<form action="'+data.url+'" method="POST"></form>');
                                 $('#excelValid').parent().append(rfrom);
                                 rfrom.submit();
                                 rfrom.remove();*!/
                                 window.open(data.url,"_blank");
                                 console.log(data.url);
                             }
                             parent.layer.msg(data.Message,{icon:1,time:2000});
                             parent.getList();
                             var index = parent.layer.getFrameIndex(window.name);
                             parent.layer.close(index);
                         }
                         else {
                           //  $.Showmsg(data.Message);
                             parent.layer.msg(data.Message,{icon:2,time:2000});
                         }
                     }
                 });
                 return false;
             }
         });
     }*/


    /**需求申报管理**/
    $('#apply_add').click(function () {
        location = '/PersonDemand/applyadd?id=';
    });
    $('#apply_edit').click(function () {
        EditInfo1('/PersonDemand/applyadd?_x=2015');
    });
    $('#apply_del').click(function () {
        DelInfo('/PersonDemand/DelApplyAction');
    });
    $('#apply_view').click(function () {
        EditInfo3('/PersonDemand/applyview?_x=2015');
    });
    $('#apply_submit').click(function () {
        DelInfo('/PersonDemand/applysubmit');
    });
    $('#apply_hraudit').click(function () {
        EditInfo1('/PersonDemand/applyhraudit?_x=2015');
    });

    $('#apply_audit').click(function () {
        EditInfo1('/PersonDemand/applyaudit?_x=2015');
    });


    /**招聘计划管理**/
    $('#plan_add').click(function () {
        location = '/Plan/add';
    });
    $('#plan_edit').click(function () {
        EditInfo1('/Plan/edit?_x=2015');
    });
    $('#plan_del').click(function () {
        layer.confirm('确定要删除该条信息吗？', {
            btn: ['是', '否']
        }, function () {
            DelInfo('/Plan/DelAction');
            layer.closeAll();
        }, function () {
            layer.closeAll();
        });
    });
    $('#plan_view').click(function () {
        EditInfo('查看招聘计划', '/Plan/view?_x=2015', '98%', '96%');
    });
    $('#plan_publish').click(function () {
        DelInfo('/Plan/PublishAction');
    });

    /*****************************************招聘方案****************************************************/
    /**
     * 添加招聘方案
     */
    $('#project_add').click(function () {
        location = '/Project/add';
    });

    /**
     * 编辑招聘方案
     */
    $('#project_edit').click(function () {
        layui.use('table', function () {
            var table = layui.table;
            var id = '';
            var checkStatusTemp = table.checkStatus("projectIndexTable"); //idTest 即为基础参数 id 对应的值

            // console.log(checkStatusTemp.data) //获取选中行的数据
            // console.log(checkStatusTemp.data.length) //获取选中行数量，可作为是否有选中行的条件
            // console.log(checkStatusTemp.isAll) //表格是否全选

            if (checkStatusTemp.data.length < 1) {
                layer.alert("请选择一条信息！", {icon: 7});
            } else if (checkStatusTemp.data.length > 1) {
                layer.alert("只能选择一条信息！", {icon: 7});
            } else {
                id = checkStatusTemp.data[0].id_cb.replace('cb_', '') + '&';

                location = '/Project/add?_x=2019' + '&id=' + id;
            }
        });
    });

    /**
     * 删除招聘方案
     */
    $('#project_del').click(function () {
        layer.confirm('确定要删除该条信息吗？', {
            yes: function () {
                //  DelInfo('/Project/DelAction');
                //监听复选框选择情况
                delTableList('projectIndexTable', '/Project/DelAction', recruitPlanTable, '/Project/getProListLayuiJson');
                layer.closeAll();
            }
        }, function (index) {
            layer.closeAll();
        });
    });
    /**
     * 发布招聘方案
     */
    $('#project_publish').click(function () {
        //  EditInfo('发布招聘方案', '/Project/pub?_x=2015', '500px', '430px');
        editTableListFram1('发布招聘方案', 'projectIndexTable', '/Project/pub?_x=2015', '500px', '400px');
    });

    /**
     * 查看招聘方案
     */
    $('#project_view').click(function () {
        // EditInfo('查看招聘方案', '/Project/view?_x=2015', '90%', '600px');
        editTableListFram1('查看招聘方案', 'projectIndexTable', '/Project/view?_x=2015', '50%', '600px');
    });
    /**
     * 关闭招聘方案
     */

    $('#project_close').click(function () {
        layer.confirm('确定要关闭该条信息吗？', {
            yes: function () {
                //监听复选框选择情况
                delTableList('projectIndexTable', '/Project/CloseActions', recruitPlanTable, '/Project/getProListLayuiJson');
                layer.closeAll();
            }
        }, function (index) {
            layer.closeAll();
        });
    });

    /**
     * 启用/停用试卷
     * */
    $("#test_close").on('click', (e) => {
        delTableList('paperTable', '/PaperManager/enablePaper', paperManageTable, '/PaperManager/getPaperList?' + $("#searchform").serialize());
    });


    /**
     *  删除表格数据
     * @param tableFilter
     * @param urld
     * @param urli
     * @param tables
     */
    function delTableList(tableFilter, url, tableIns, urlIns) {
        layui.use('table', function () {
            var table = layui.table;
            var id = '';
            var checkStatusTemp = table.checkStatus(tableFilter); //idTest 即为基础参数 id 对应的值

            // console.log(checkStatusTemp.data) //获取选中行的数据
            // console.log(checkStatusTemp.data.length) //获取选中行数量，可作为是否有选中行的条件
            // console.log(checkStatusTemp.isAll ) //表格是否全选

            if (checkStatusTemp.data.length === 0) {//未选中需要删除的数据
                layer.alert("请选择要执行该操作的信息！");
            } else {//删除选中的信息
                for (var i = 0; i < checkStatusTemp.data.length; i++) {
                    id += 'id=' + checkStatusTemp.data[i].id_cb.replace('cb_', '') + '&';
                }

                postAjax(url, id, function (data) {
                    if (data.state) {
                        layui.use(['layer', 'form'], function () {
                            layer.msg(data.Message, {icon: 1})
                        });

                        //删除成功，重载数据
                        tableIns.reload(tableFilter, {
                            url: urlIns
                            , where: {} //设定异步数据接口的额外参数
                        });
                    } else {
                        layui.use(['layer', 'form'], function () {
                            layer.msg(data.Message, {icon: 2})
                        });
                    }
                });
            }

        });
    }



    /**
     * 查看数据（小窗口）
     * @param title
     * @param tableFilter
     * @param url
     * @param width
     * @param height
     */
    function editTableListFram1(title, tableFilter, url, width, height) {
        layui.use('table', function () {
            var table = layui.table;
            var id = '';
            var checkStatusTemp = table.checkStatus(tableFilter); //idTest 即为基础参数 id 对应的值

            if (checkStatusTemp.data.length < 1) {
                layer.alert("请选择一条信息！", {icon: 7});
            } else if (checkStatusTemp.data.length > 1) {
                layer.alert("只能选择一条信息！", {icon: 7});
            } else {
                id = checkStatusTemp.data[0].id_cb.replace('cb_', '') + '&';

                if (url == '/Project/pub?_x=2015')
                    openLayer2(title, url + '&id=' + id, width, height);//带关闭弹窗事件
                else
                    openLayer(title, url + '&id=' + id, width, height);

            }
        });
    }

    /**毕业生推荐**/
    $('#zzuser_view').click(function () {
        //EditInfo('查看毕业生信息', '/Do/ZZRecommend/view?_x=2015', '800px', '600px');
        EditInfoNew('查看毕业生信息', '/Do/ZZRecommend/view?_x=2015', '800px', '300px');
    });
    $('#zzuser_edit').click(function () {
        //EditInfo('修改毕业生信息', '/Do/ZZRecommend/edit?_x=2015', '500px', '350px');
        EditInfoNew('修改毕业生信息', '/Do/ZZRecommend/edit?_x=2015', '500px', '300px');
    });


    /**笔试管理**/
    $('#do_writeexam_plan').click(function () {
        location = '/Do/WriteExam/plan?flowid=' + $('input[name=flowid]').val() + '&pid=' + $('input[name=zpid]').val();
    });
    $('#do_writeexam_addplan').click(function () {
        var url = '/Do/WriteExam/addplan?flowid=' + $('input[name=flowid]').val() + '&pid=' + $('input[name=pid]').val();
        openLayer('添加笔试计划', url, '700px', '600px');
    });
    $('#do_writeexam_delplan').click(function () {
        var url = '/Do/WriteExam/DelPlanAction?flowid=' + $('input[name=flowid]').val();
        DelInfo(url);
    });
    $('#do_writeexam_publish').click(function () {
        EditInfo('发布笔试通知', '/Do/WriteExam/publish?flowid=' + $('input[name=flowid]').val(), '700px', '300px');
    });
    $('#do_writeexam_score').click(function () {
        EditInfo('登记结果', '/Do/WriteExam/score?flowid=' + $('input[name=flowid]').val(), '700px', '300px');
    });
    $('#do_writeexam_next').click(function () {
        var url = '/Do/WriteExam/next?id=' + $('input[name=zpid]').val() + '&flowid=' + $('input[name=flowid]').val();
        openLayer('进入下一环节', url, '700px', '600px');
    });

    /**面试管理**/
    $('#do_interview_plan').click(function () {
        location = '/Do/Interview/plan?id=' + $('input[name=fid]').val() + '&pid=' + $('input[name=zpid]').val();
    });
    $('#do_interview_addplan').click(function () {
        location = '/Do/Interview/addplan?id=' + $('input[name=id]').val() + '&pid=' + $('input[name=pid]').val();
    });
    $('#do_interview_editplan').click(function () {
        EditInfo1('/Do/Interview/editplan?pid=' + $('input[name=pid]').val());
    });
    $('#do_interview_delplan').click(function () {
        DelInfo('/Do/Interview/DelPlanAction?fid=' + $('input[name=id]').val());
    });
    $('#do_interview_publish').click(function () {
        EditInfo('发布短信通知', '/Do/Interview/publish?fid=' + $('input[name=id]').val(), '700px', '400px');
    });
    $('#do_interview_score').click(function () {
        EditInfo('登记结果', '/Do/Interview/score?fid=' + $('input[name=fid]').val(), '700px', '600px');
    });
    $('#do_interview_next').click(function () {
        var url = '/Do/Interview/next?id=' + $('input[name=zpid]').val() + '&flowid=' + $('input[name=fid]').val();
        openLayer('转到下一环节', url, '700px', '200px');
    });

    /**背景调查管理**/
    $('#do_political_score').click(function () {
        EditInfo('登记结果', '/Do/Political/score?fid=' + $('input[name=fid]').val(), '500px', '300px');
    });
    $('#do_political_next').click(function () {
        var url = '/Do/Political/NextAction?id=' + $('input[name=zpid]').val() + '&flowid=' + $('input[name=fid]').val();
        postAjax(url, null, function (data) {
            $.Showmsg(data.Message);
            if (data.url != 'no') {
                location = data.url;
            }
        });
    });

    /**体检管理**/
    $('#do_physical_plan').click(function () {
        location = '/Do/Physical/plan?id=' + $('input[name=fid]').val() + '&pid=' + $('input[name=zpid]').val();
    });
    $('#do_physical_addplan').click(function () {
        location = '/Do/Physical/addplan?id=' + $('input[name=id]').val() + '&pid=' + $('input[name=pid]').val();
    });
    $('#do_physical_editplan').click(function () {
        EditInfo1('/Do/Physical/editplan?pid=' + $('input[name=pid]').val());
    });
    $('#do_physical_delplan').click(function () {
        DelInfo('/Do/Physical/DelPlanAction?fid=' + $('input[name=id]').val());
    });
    $('#do_physical_publish').click(function () {
        EditInfo('发布短信通知', '/Do/Physical/publish?_x=2015', '700px', '400px');
    });
    $('#do_physical_score').click(function () {
        EditInfo('登记结果', '/Do/Physical/score?_x=2015', '500px', '300px');
    });
    $('#do_physical_next').click(function () {
        var url = '/Do/Physical/NextAction?id=' + $('input[name=zpid]').val() + '&flowid=' + $('input[name=fid]').val();
        postAjax(url, null, function (data) {
            $.Showmsg(data.Message);
            if (data.url != 'no') {
                location = data.url;
            }
        });
    });

    /**录用管理**/
    $('#do_employment_score').click(function () {
        EditInfo('登记结果', '/Do/Employment/score?_x=2015', '500px', '300px');
    });
    $('#do_employment_done').click(function () {
        var url = '/Do/Employment/NextAction?id=' + $('input[name=zpid]').val() + '&flowid=' + $('input[name=fid]').val();
        postAjax(url, null, function (data) {
            $.Showmsg(data.Message);
            if (data.url != 'no') {
                location = data.url;
            }
        });
    });

    /**
     * 下载简历word
     */
    $('#download_resume').click(function () {
        getTableChecks();
        var id = '';
        var selectData = layui.table.checkStatus('listTables').data;

        if (selectData.length === 0) {
            parent.layer.alert("至少选择1条信息！", {icon: 2});
        }else if (selectData.length > 10) {
            parent.layer.alert("一次最多只能选择10条信息！", {icon: 2});
        } else {
            for (var i = 0; i < selectData.length; i++) {
                id += 'id=' + selectData[i].id_cb.replace('cb_', '') + '&';
            }
            $.post("/AppendOut/OutputByWord?type=1&" + id, function (json) {
                if (json.state) {
                    var urls = json.url.split(',');
                    var lens = urls.length - 1;
                    for (var i = 0; i < lens; i++) {
                        if (window.navigator.appName == 'Microsoft Internet Explorer') {  // IE
                            window.open(urls[i], '_blank');
                        } else {
                            let a = document.createElement('a');// 创建a标签
                            let e = document.createEvent('MouseEvents'); // 创建鼠标事件对象
                            e.initEvent('click', false, false); // 初始化事件对象
                            a.href = urls[i];// 设置下载地址
                            a.download = ''; // 设置下载文件名
                            a.dispatchEvent(e);
                        }
                    }
                    layer.alert(json.Message + "\n已下载" + lens + "份简历。", {icon: 1});
                } else {
                    layer.alert(json.Message, {icon: 2});
                }
            }, "json")
        }
    });

    /**
     * 下载简历压缩包
     */
    $('#resume_down_zip').click(function(){
        var url = '/AppendOut/DUserResume/OutputByWordAction';
        getTableChecks();
        var ids = '';
        //  var checkedIds=$('.allcheckbox').data('checkIds');
        var selectData = layui.table.checkStatus('listTables').data;
        var jobs=$('#searchbox select[name="jname"]').val();
        var proid=$('#searchbox input[name="proid"]').val();
        if(!!jobs){
            if(selectData.length === 0) {
                parent.layer.confirm('您尚未选择要导出的简历,是否下载<span style="color: red">' + jobs + '</span>,下全部简历?', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    postAjax(url, {jobs: jobs,proid:proid}, function (data) {
                        if (data.state) {
                            if (window.navigator.appName == 'Microsoft Internet Explorer') {  // IE
                                window.open(data.url, '_blank');
                            } else {
                                let a = document.createElement('a');// 创建a标签
                                let e = document.createEvent('MouseEvents'); // 创建鼠标事件对象
                                e.initEvent('click', false, false); // 初始化事件对象
                                a.href = data.url;// 设置下载地址
                                a.download = ''; // 设置下载文件名
                                a.dispatchEvent(e);
                            }
                            parent.layer.alert(data.Message, {icon: 1, time: 2000});
                        } else {
                            parent.layer.alert(data.Message, {icon: 2, time: 2000});
                        }
                    });

                }, function (index) {
                    layer.close(index);
                });
            }else{
                parent.layer.confirm('是否下载<span style="color: red">' + jobs + '</span>,下是否下载<span style="color: red">' + selectData.length + '</span>人的简历?', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    url=url+"?proid="+proid+"&jobs="+jobs;
                    for(var i=0;i<selectData.length;i++){
                        ids += 'id=' +selectData[i].id_cb.replace('cb_', '') +'&';
                    }
                    postAjax(url, ids, function (data) {
                        if (data.state) {
                            if (window.navigator.appName == 'Microsoft Internet Explorer') {  // IE
                                window.open(data.url, '_blank');
                            } else {
                                let a = document.createElement('a');// 创建a标签
                                let e = document.createEvent('MouseEvents'); // 创建鼠标事件对象
                                e.initEvent('click', false, false); // 初始化事件对象
                                a.href = data.url;// 设置下载地址
                                a.download = ''; // 设置下载文件名
                                a.dispatchEvent(e);
                            }
                            parent.layer.alert(data.Message, {icon: 1, time: 2000});
                        } else {
                            parent.layer.alert(data.Message, {icon: 2, time: 2000});
                        }
                    });

                }, function (index) {
                    layer.close(index);
                });
            }
        }else{
            if(selectData.length === 0){
                parent.layer.alert("至少选择1条信息！", {icon: 2});
            }else{
                for(var i=0;i<selectData.length;i++){
                    ids += 'id=' +selectData[i].id_cb.replace('cb_', '') +'&';
                }
                postAjax(url, ids, function (data) {
                    if (data.state) {
                        if (window.navigator.appName == 'Microsoft Internet Explorer') {  // IE
                            window.open(data.url, '_blank');
                        } else {
                            let a = document.createElement('a');// 创建a标签
                            let e = document.createEvent('MouseEvents'); // 创建鼠标事件对象
                            e.initEvent('click', false, false); // 初始化事件对象
                            a.href = data.url;// 设置下载地址
                            a.download = ''; // 设置下载文件名
                            a.dispatchEvent(e);
                        }
                        parent.layer.alert(data.Message, {icon: 1,time:2000});
                    }
                    else {
                        parent.layer.alert(data.Message, {icon: 2,time:2000});
                    }
                });
            }

        }
    });

    /**内容管理**/
    $('#cms_add').click(function () {
        location = '/CMS/add';
    });
    $('#cms_edit').click(function () {
        //EditInfo1('/CMS/edit?_x=2015');
    });
    $('#cms_del').click(function () {
        DelInfo('/CMS/DelAction');
    });

    /**人才库管理**/
    // $('#talentpoolout').click(function () {
    //     DelInfo('/talentpool/RemoveAction');
    // });

    /**公布实施阶段结果（已公布->未公布/未公布->已公布）**/
    $('#publishresult').click(function () {
        // var bobj = $(this);
        var fidTemp = GetQueryString('fid');
        var deptcodeTemp = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“未公布”设置成“已公布”<br>2、“已公布”设置成“未公布”<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            //  DelInfo('/Do/SZ/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            DelInfoNew('/Do/SZ/PublishResultAction?fid=' + fidTemp + '&deptcode=' + deptcodeTemp);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });
    $('#nzpublishresult').click(function () {
        // var bobj = $(this);
        var fidTemp = GetQueryString('fid');
        var deptcodeTemp = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“未公布”设置成“已公布”<br>2、“已公布”设置成“未公布”<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            DelInfoNew('/Do/NZ/PublishResultAction?fid=' + fidTemp + '&deptcode=' + deptcodeTemp);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });

    $('#gxpublishresult').click(function () {
        var fidTemp = GetQueryString('fid');
        var deptcodeTemp = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“未公布”设置成“已公布”<br>2、“已公布”设置成“未公布”<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            //  DelInfo('/DUserResume/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            DelInfoNew('/DUserResume/PublishResultAction?fid=' + fidTemp + '&deptcode=' + deptcodeTemp);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });

    $('#gxpublisharrange').click(function () {
        var fidTemp = GetQueryString('fid');
        var deptcodeTemp = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“安排未公布”设置成“安排已公布”<br>2、“安排已公布”设置成“安排未公布”<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            //  DelInfo('/DUserResume/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            DelInfoNew('/DUserResume/PublishArrangeAction?fid=' + fidTemp + '&deptcode=' + deptcodeTemp);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });

    $('#mspublishresult').click(function () {
        //var bobj = $(this);
        var fidTemp = GetQueryString('fid');
        var deptcodeTemp = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“未公布”设置成“已公布”<br>2、“已公布”设置成“未公布”<br>3、面试环节仅会发不面试安排信息,面试结果请在背景调查中进行发布!<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            //DelInfo('/DUserResume/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            DelInfoNew('/DUserResume/PublishResultAction?fid=' + fidTemp + '&deptcode=' + deptcodeTemp);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });


    $('#mspublishresult2').click(function () {
        parent.layer.confirm('请将应聘者流转至背景调查环节进行统一发布！', {
            btn: ['是', '否']
        }, function () {
            //DelInfo('/Do/GXCampus/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });

    $('#zzpublishresult').click(function () {
        //  var bobj = $(this);
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');
        parent.layer.confirm('将要执行以下操作：<br>1、“未公布”设置成“已公布”<br>2、“已公布”设置成“未公布”<br>确定要执行吗？', {
            btn: ['是', '否']
        }, function () {
            // DelInfo('/Do/ZZCampus/PublishResultAction?fid=' + bobj.attr('fid') + '&deptcode=' + bobj.attr('deptcode'));
            DelInfoNew('/Do/ZZCampus/PublishResultAction?fid=' + rFid + '&deptcode=' + rDeptcode);
            parent.layer.closeAll();
        }, function () {
            parent.layer.closeAll();
        });
    });

    $('#dosz_tjgwNew').click(function () {
        //var tboj = $(this);
        var rPid = GetQueryString('pid');
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');
        var id = '';
        var selectData = layui.table.checkStatus('listTables').data;

        if (selectData.length == 0) {
            layer.msg("请选择要执行该操作的信息！", {icon: 2});
        } else {
            for (var i = 0; i < selectData.length; i++) {
                id += 'id=' + selectData[i].id_cb.replace('cb_', '') + '&';
            }
            parent.openLayer('推荐到其他岗位', '/Do/SZ/RecommendPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode + '&' + id, '60%', '60%');
        }
    });
    $('#dosz_tjgw').click(function () {
        //var tboj = $(this);
        var rPid = GetQueryString('pid');
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');
        var id = '';
        var count = 0;
        $('#tablelist tbody input[type=checkbox]').each(function () {
            if ($(this).is(":checked")) {
                count++;
                id += 'id=' + $(this).attr('id').replace('cb_', '') + '&';
            }
        });
        if (count == 0) {
            layer.alert('请选择要执行该操作的信息', {icon: 5, time: 5000});
        } else {
            //parent.openpLayer('推荐到其他岗位', '/Do/SZ/RecommendPost?pid=' + tboj.attr('pid') + '&fid=' + tboj.attr('fid') + '&deptcode=' + tboj.attr('deptcode') + '&' + id, '60%', '90%');
            // parent.openpLayer('推荐到其他岗位', '/Do/SZ/RecommendPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode+ '&' + id, '60%', '60%');
            parent.openLayer('推荐到其他岗位', '/Do/SZ/RecommendPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode + '&' + id, '60%', '60%');

        }
    });

    $('#do_tjgwNew').click(function () {
        //  var tboj = $(this);
        var rPid = GetQueryString('pid');
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');

        var id = '';
        var selectData = layui.table.checkStatus('listTables').data;

        if (selectData.length == 0) {
            layer.msg("请选择要执行该操作的信息！", {icon: 2});
        } else {
            for (var i = 0; i < selectData.length; i++) {
                id += 'id=' + selectData[i].id_cb.replace('cb_', '') + '&';
            }
            openpLayer('推荐到其他岗位', '/DUserResume/RecommendPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode + '&' + id, '60%', '60%');
        }
    });

    $('#do_tjgw').click(function () {
        //  var tboj = $(this);
        var rPid = GetQueryString('pid');
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');
        var id = '';
        var count = 0;
        $('#tablelist tbody input[type=checkbox]').each(function () {
            if ($(this).is(":checked")) {
                count++;
                id += 'id=' + $(this).attr('id').replace('cb_', '') + '&';
            }
        });
        if (count == 0) {
            parent.layer.alert('请选择要执行该操作的信息', {icon: 5, time: 5000});
        } else {
            // openpLayer('推荐到其他岗位', '/DUserResume/RecommendPost?pid=' + tboj.attr('pid') + '&fid=' + tboj.attr('fid') + '&deptcode=' + tboj.attr('deptcode') + '&' + id, '60%', '90%');
            openpLayer('推荐到其他岗位', '/DUserResume/RecommendPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode + '&' + id, '60%', '60%');

        }
    });

    $('#do_gwpp').click(function () {
        // var tboj = $(this);
        var rPid = GetQueryString('pid');
        var rFid = GetQueryString('fid');
        var rDeptcode = GetQueryString('deptcode');
        // openLayer('岗位匹配', '/DUserResume/MatchingPost?pid=' + tboj.attr('pid') + '&fid=' + tboj.attr('fid') + '&deptcode=' + tboj.attr('deptcode') , '70%', '90%');
        openLayer('岗位匹配', '/DUserResume/MatchingPost?pid=' + rPid + '&fid=' + rFid + '&deptcode=' + rDeptcode, '70%', '90%');
    });

    /* 全选/取消全选
    -------------------------------------------------*/
    $(document).delegate('.allcheckbox', 'click', function () {
        $(this).parent().parent().parent().next().find('input[type=checkbox]').each(function () {
            var tr = $(this).parent().parent();
            if ($(".allcheckbox").is(":checked")) {
                this.checked = true;
                tr.addClass('checked');
            } else {
                this.checked = false;
                tr.removeClass('checked');
            }
        });
    });

    /* 选择单行
    -------------------------------------------------*/
    $(document).delegate('#tablelist tbody tr', 'click', function () {
        var ck = $(this).find('input[type=checkbox]');
        if (ck.is(":checked")) {
            $(this).addClass('checked');
            ck.checked = true;
        } else {
            $(this).removeClass('checked');
            ck.checked = false;
        }
    });
    /* 单选
    -------------------------------------------------*/
    $(document).delegate('.inputform tbody div.radio span', 'click', function () {
        if (!$(this).parent().hasClass('disables')) {
            $(this).parent().find('span').removeClass('checked');
            $(this).addClass('checked');
            $(this).parent().find('input[type=hidden]').val($(this).attr('rel'));
        }
    });
});



//获取页面的url参数的值
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

//获取父页面的url参数的值
function GetParentQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.parent.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

//获取URL参数值/多个同名参数值
function getUrlVal(para) {
    var search = location.search; //页面URL的查询部分字符串
    var arrPara = new Array(); //参数数组。数组单项为包含参数名和参数值的字符串，如“para=value”
    var arrVal = new Array(); //参数值数组。用于存储查找到的参数值

    if (search != "") {
        var index = 0;
        search = search.substr(1); //去除开头的“?”
        arrPara = search.split("&");

        var i = 0;

        for (i in arrPara) {
            var paraPre = para + "="; //参数前缀。即参数名+“=”，如“para=”
            if (arrPara[i].indexOf(paraPre) == 0 && paraPre.length < arrPara[i].length) {
                arrVal[index] = decodeURI(arrPara[i].substr(paraPre.length)); //顺带URI解码避免出现乱码
                index++;
            }
        }
    }

    if (arrVal.length == 1) {
        return arrVal[0];
    } else if (arrVal.length == 0) {
        return null;
    } else {
        return arrVal;
    }
}

//页面样式渲染
function setWidth() {
    $('select').each(function () {
        var sid = $(this).attr("id");
        if (sid != 'province' && sid != 'city' && sid != 'area' && sid != 'street') {
            $(this).css('width', $(this).parent().width() - 5);
        }
    });
    $('textarea').each(function () {
        $(this).css('width', $(this).parent().width() - 17);
    });
    $('input[type=text]').each(function () {
        $(this).css('width', $(this).parent().width() - parseFloat($(this).css("padding-left").replace('px', '')) - parseFloat($(this).css("padding-right").replace('px', '')) - 7);
    });
}

//打开窗口页面
function openLayer(title, url, width, height) {
    layer.open({
        type: 2,
        title: title,
        shade: 0.5,
        area: [width, height],
        content: encodeURI(url)
    });
}


//var upProjectPubFlag = false; //发布招聘方案的标志
//打开窗口页面
function openLayer2(title, url, width, height) {
    layer.open({
        type: 2,
        title: title,
        shade: 0.5,
        area: [width, height],
        content: encodeURI(url),
        end: function () {
            layui.use('table', function () {
                //更新数据
                recruitPlanTable.reload('projectIndexTable', {
                    url: '/Project/getProListLayuiJson'
                    , where: {} //设定异步数据接口的额外参数
                });
            });
        }
    });
}

//父窗口弹出层
function openpLayer(title, url, width, height) {
    parent.layer.open({
        type: 2,
        title: title,
        shade: 0.5,
        area: [width, height],
        content: encodeURI(url)
    });
}
//父窗口弹出层
function openpLayerClo(title, url, width, height) {
    parent.layer.open({
        type: 2,
        title: title,
        shade: 0.5,
        area: [width, height],
        content: encodeURI(url),
        cancel: function(){ // 右上角关闭事件的逻辑
            location.reload();
        }
    });
}

/*
只能选择一个选项的
 */
function LEditInfo(title, url, width, height, tableId = 'table') {
    let chosendata = layui.table.checkStatus(tableId).data;
    if (chosendata.length < 1) {
        layer.msg('请选择一条信息', {icon: 7, time: 2000});
    } else if (chosendata.length > 1) {
        layer.msg('只能选择一条信息', {icon: 7, time: 2000});
    } else {
        openLayer(title, url + '&id=' + chosendata[0].id, width, height);
    }
}

/*
可以选择多个选项的,无界面
 */
function LDeleteInfo(url, success, fail, tableId = 'table', rqs = null) {
    let chosendata = layui.table.checkStatus(tableId).data;
    if (rqs == null) {
        rqs = chosendata.map((item, index, array) => {
            return {name: "id", value: item.id};
        });
    }
    if (chosendata.length === 0) {
        layer.msg('请选择要执行该操作的信息', {icon: 7, time: 2000});
    } else {
        postAjax(url
            , rqs
            , success
            , fail)
    }
}

//修改信息
function EditInfoNew(title, url, width, height) {
    var id = '';
    var selectData = layui.table.checkStatus('listTables').data;
    if (selectData.length == 0) {
        parent.layer.alert('请选择一条信息!', {icon: 2});
    } else if (selectData.length > 1) {
        parent.layer.alert('只能选择一条信息!', {icon: 2});
    } else {
        id = selectData[0].id_cb.replace('cb_', '') + '';
        openLayer(title, url + '&id=' + id, width, height);
    }
    /* var count = 0;
     $('#tablelist tbody input[type=checkbox]').each(function () {
         if ($(this).is(":checked")) {
             count++;
             id = $(this).attr('id').replace('cb_', '');
         }
     });
     if (count < 1) {
         //$.Showmsg('请选择一条信息');
         layer.msg('请选择一条信息',{icon:7,time:2000});
     } else if (count > 1) {
         //$.Showmsg('只能选择一条信息');
         layer.msg('只能选择一条信息',{icon:7,time:2000});
     } else {
         openLayer(title, url + '&id=' + id, width, height);
     }*/
}

//修改信息
function EditInfo(title, url, width, height) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id = $(this).attr('id').replace('cb_', '');
        }
    });
    if (count < 1) {
        //$.Showmsg('请选择一条信息');
        layer.msg('请选择一条信息', {icon: 7, time: 2000});
    } else if (count > 1) {
        //$.Showmsg('只能选择一条信息');
        layer.msg('只能选择一条信息', {icon: 7, time: 2000});
    } else {
        openLayer(title, url + '&id=' + id, width, height);
    }
}

//修改信息
function EditInfo1(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id = $(this).attr('id').replace('cb_', '');
        }
    });
    if (count < 1) {
        //$.Showmsg('请选择一条信息');
        layer.msg('请选择一条信息', {icon: 7, time: 2000});
    } else if (count > 1) {
        //$.Showmsg('只能选择一条信息');
        layer.msg('只能选择一条信息', {icon: 7, time: 2000});
    } else {
        location = url + '&id=' + id;
    }
}

//修改信息
function EditInfo2(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id = $(this).attr('id').replace('cb_', '');
        }
    });
    if (count < 1) {
        //  $.Showmsg('请选择一条信息');
        layer.msg('请选择一条信息', {icon: 7, time: 2000});
    } else if (count > 1) {
        // $.Showmsg('只能选择一条信息');
        layer.msg('只能选择一条信息', {icon: 7, time: 2000});
    } else {
        location = url + '&id=' + id;
    }
}

//修改信息
function EditInfo3(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id = $(this).attr('id').replace('cb_', '');
        }
    });
    if (count < 1) {
        //$.Showmsg('请选择一条信息');
        layer.msg('请选择一条信息', {icon: 7, time: 2000});
    } else if (count > 1) {
        // $.Showmsg('只能选择一条信息');
        layer.msg('只能选择一条信息', {icon: 7, time: 2000});
    } else {
        window.open(url + '&id=' + id);
    }
}

//删除信息
function DelInfoNew(url) {
    var id = '';
    var selectData = layui.table.checkStatus('listTables').data;

    if (selectData.length == 0) {
        layer.msg("请选择要执行该操作的信息！", {icon: 2});
    } else {
        for (var i = 0; i < selectData.length; i++) {
            id += 'id=' + selectData[i].id_cb.replace('cb_', '') + '&';
        }

        postAjax(url, id, function (data) {
            if (data.state) {
                layer.msg(data.Message, {icon: 1});
                tableRenders();
            } else {
                layer.msg(data.Message, {icon: 2});
            }
        });
    }
}

//删除信息
function DelInfo(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id += 'id=' + $(this).attr('id').replace('cb_', '') + '&';
        }
    });
    if (count == 0) {
        // $.Showmsg('请选择要执行该操作的信息');
        layer.msg("请选择要执行该操作的信息！", {icon: 2});
        //parent.layer.alert('请选择要执行该操作的信息',{icon:2,time:2000});
    } else {
        postAjax(url, id, function (data) {
            if (data.state) {
                //  $.Showmsg(data.Message);
                layer.msg(data.Message, {icon: 1});
                // parent.layer.msg(data.Message,{icon:1,time:2000});
                getList();
            } else {
                // parent.layer.msg(data.Message,{icon:2,time:2000});
                // $.Showmsg(data.Message);
                layer.msg(data.Message, {icon: 2});
            }
        });
    }
}

//删除信息
function DelInfo1(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id = $(this).attr('id').replace('cb_', '');
        }
    });
    if (count == 1) {
        postAjax(url + '&id=' + id, null, function (data) {
            if (data.state) {
                $.Showmsg(data.Message);
                getList();
            } else {
                $.Showmsg(data.Message);
            }
        });
    } else {
        // $.Showmsg('请选择一条需要执行该操作的信息');
        layer.msg('请选择一条需要执行该操作的信息', {icon: 7, time: 2000});
    }
}

/**
 * 批量操作数据，成功后刷新当前分页数据
 * @param url
 */
function cgMoreData(url) {
    var id = '';
    var count = 0;
    $('#tablelist tbody input[type=checkbox]').each(function () {
        if ($(this).is(":checked")) {
            count++;
            id += 'id=' + $(this).attr('id').replace('cb_', '') + '&';
        }
    });
    if (count == 0) {
        //$.Showmsg('请选择要执行该操作的信息');
        layer.msg('请选择要执行该操作的信息', {icon: 7, time: 2000});
    } else {
        postAjax(url, id, function (data) {
            if (data.state) {
                $.Showmsg(data.Message);
                reloadData();
            } else {
                $.Showmsg(data.Message);
            }
        });
    }
}

function cgMoreData1(url) {
    var id = '';
    var checkedIds = $('.allcheckbox').data('checkIds');
    if (!!!checkedIds) {
        parent.layer.alert('请选择要执行该操作的信息', {icon: 5, time: 5000});
    } else {
        for (var i = 0; i < checkedIds.length; i++) {
            id += 'id=' + checkedIds[i].toString().replace('cb_', '') + '&';
        }
        postAjax(url, id, function (data) {
            if (data.state) {
                parent.layer.alert(data.Message, {icon: 6, time: 2000});
                reloadData();
            } else {
                parent.layer.alert(data.Message, {icon: 5, time: 2000});
            }
        });
    }
}

/**
 * 批量执行
 * url:方法地址
 * idobj:存放主键集合的容器ID
 */
function SubmitAll(url, idobj) {
    var id = '';
    var count = 0;
    $('#' + idobj + ' input').each(function () {
        count++;
        id += 'id=' + $(this).val() + '&';
    });
    if (count == 0) {
        layer.alert('请选择要执行该操作的信息', {icon: 5, time: 5000});
    } else {
        postAjax(url, id, function (data) {
            if (data.state) {
                parent.layer.alert(data.Message, {icon: 6, time: 5000});
                getList();
            } else {
                parent.layer.alert(data.Message, {icon: 5, time: 5000});
            }
        });
    }
}

function toNextFlowNew(url, nowflow) {
    var id = '';
    var selectData = layui.table.checkStatus('listTables').data;

    if (selectData.length == 0) {
        layer.msg("请选择要执行该操作的信息！", {icon: 2});
    } else {
        for (var i = 0; i < selectData.length; i++) {
            id += 'id=' + selectData[i].id_cb.replace('cb_', '') + '&';
        }
        postAjax(url, id, function (data) {
            if (data.state) {
                parent.layer.alert(data.Message, {icon: 1, time: 2000});
                tableRenders();
                var Timer = setTimeout(changeToNextTab(nowflow), 500);
                clearTimeout(1);
            } else {
                parent.layer.alert(data.Message, {icon: 2, time: 2000});
            }
        });
    }
}

function toNextFlow(url, nowflow) {
    var id = '';
    var checkedIds = $('.allcheckbox').data('checkIds');
    if (!!!checkedIds) {
        parent.layer.alert('请选择要执行该操作的信息', {icon: 5, time: 5000});
    } else {
        for (var i = 0; i < checkedIds.length; i++) {
            id += 'id=' + checkedIds[i].toString().replace('cb_', '') + '&';
        }
        postAjax(url, id, function (data) {
            if (data.state) {
                parent.layer.alert(data.Message, {icon: 6, time: 5000});
                getList();
                var Timer = setTimeout(changeToNextTab(nowflow), 500);
                clearTimeout(1);

            } else {
                parent.layer.alert(data.Message, {icon: 5, time: 5000});
            }
        });
    }
}

function changeToNextTab(fid) {
    var allflows = parent.allflows;
    var nextflow = '';
    if (allflows.length > 0) {
        for (var i = 0; i < allflows.length; i++) {
            if (allflows[i] == fid) {
                nextflow = allflows[i + 1];
                break;
            }
        }
    }
    var Time2 = setTimeout(parent.loadTab(nextflow), 300);
    clearTimeout(Time2);
    //parent.loadTab(nextflow);
}

//通过POST方式请求Ajax 带返回值
function postAjax(url, parm, success, fail) {
    var load = null;
    $.ajax({
        type: 'post',
        dataType: "json",
        url: url,
        data: parm,
        cache: false,
        async: true,
        beforeSend: function (e) {
            load = layer.load('努力加载中...');
        },
        error: function () {
            layer.close(load);
            layer.alert('连接服务器失败', {icon: 5, time: 5000});
            if (!!fail) {
                fail();
            }
        },
        success: function (msg) {
            layer.close(load);
            if (!!success) {
                success(msg);
            }
        }
    });
}

//通过GET方式请求Ajax 带返回值
function getJson(url, callBack) {
    var load = null;
    $.ajax({
        type: 'get',
        dataType: "json",
        url: url,
        cache: false,
        async: true,
        beforeSend: function (e) {
            load = layer.load('努力加载中...');
        },
        success: function (msg) {
            layer.close(load);
            callBack(msg);
        }
    });
}


function getAjax(url, parm, callBack) {
    var load = null;
    $.ajax({
        type: 'get',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: true,
        beforeSend: function (e) {
            load = layer.load('努力加载中...');
        },
        success: function (msg) {
            layer.close(load);
            callBack(msg);
        }
    });
}

function getAjax1(url, parm, callBack) {
    $.ajax({
        type: 'get',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}

//获得URL参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

//初始化单选控件选中值
function initCheckVal() {
    $('.radio input[type=hidden]').each(function () {
        var val = $(this).val();
        $(this).parent().find('span').each(function () {
            if ($(this).attr('rel') == val) {
                $(this).addClass('checked');
            }
        });
    });

    $('select').each(function () {
        $(this).val($(this).prev().val());
    });
}

//显示隐藏更多筛选条件
function moreparam() {
    $('#showhidebtn').blur();
    if ($('.moretj').is(":visible")) {
        $('.moretj').hide();
        $('#showhidebtn').removeClass('moretjbtn1').addClass('moretjbtn0').attr('title', '高级查询');
    } else {
        $('.moretj').show();
        $('#showhidebtn').removeClass('moretjbtn0').addClass('moretjbtn1').attr('title', '简单查询');
    }
    parent.changeFrameHeight();
}

//页面加载完成后关闭进度条
function initView() {
    setTimeout(function () {
        $('#loader').hide();
    }, 200);
}

//初始化searchbox中状态选择项
function fillSelectState(name, fid) {
    $.post("/DUserResume/getFlowStateJson", {fid: fid}, function (result) {
        if (result.state) {
            $("#searchbox select[name='" + name + "']").empty();
            if (!!result.datas && result.datas.length > 0) {
                $(result.datas).each(function (i, v) {
                    //console.log(v);
                    if (v != "全部") {
                        $('#searchbox select[name=' + name + ']').append('<option value="' + v + '">' + v + '</option>')
                    } else {
                        $('#searchbox select[name=' + name + ']').append('<option value="">' + v + '</option>');
                    }

                })
            }
        } else {
            parent.layer.alert(result.Message, {icon: 2});
        }
    }, "JSON");
}